<template>
  <div>
    <div slot="header" class="clearfix" style="padding-bottom: 0px">
      <span>打卡记录</span>
    </div>
    <el-row>
      <el-card shadow="hover" style="height: 200">
        <el-table :data="recordList" stripe style="width: 100%">
          <el-table-column prop="uid" label="用户ID" width="150">
          </el-table-column>
          <el-table-column prop="udept" label="学院" width="150">
          </el-table-column>
          <el-table-column prop="uname" label="姓名" width="150">
          </el-table-column>
          <el-table-column prop="health" label="健康状况" width="150">
          </el-table-column>
          <el-table-column prop="temperature" label="体温" width="150">
          </el-table-column>
          <el-table-column prop="isOut" label="是否外出" width="100">
          </el-table-column>
          <el-table-column prop="rtime" label="填报时间" width="200">
          </el-table-column>
          <el-table-column prop="workState" label="工作状态" width="100">
          </el-table-column>
          <el-table-column prop="remark" label="备注"> </el-table-column>
        </el-table>
      </el-card>
    </el-row>
    <div slot="header" class="clearfix" style="padding-bottom: 10px">
      <span>未登记人员信息</span>
    </div>
    <el-row>
      <el-card shadow="hover" style="height: 200px">
        <el-table :data="absentUserlist" stripe style="width: 100%">
          <el-table-column prop="uid" label="用户ID" width="250">
          </el-table-column>
          <el-table-column prop="udept" label="学院" width="300">
          </el-table-column>
          <el-table-column prop="uname" label="姓名" width="300">
          </el-table-column>
          <el-table-column prop="absenceCount" label="未登记次数" width="300">
          </el-table-column>
          <el-table-column
            prop="absenceTime"
            label="最近一次未登记时间"
            width="300"
          >
          </el-table-column>
        </el-table>
      </el-card>
    </el-row>

    <div slot="header" class="clearfix" style="padding-bottom: 10px">
      <span>用户管理</span>
    </div>
    <el-row>
      <el-card shadow="hover" style="height: 200px">
        <el-table :data="userlist" stripe style="width: 100%">
          <el-table-column prop="uid" label="用户ID" width="200">
          </el-table-column>
          <el-table-column prop="udept" label="学院" width="200">
          </el-table-column>
          <el-table-column prop="uname" label="姓名" width="250">
          </el-table-column>

          <el-table-column prop="uename" label="用户名" width="250">
          </el-table-column>

          <el-table-column prop="userOn" label="状态" width="300">
          </el-table-column>
          <el-table-column>
            <template slot-scope="scope">
              <el-button
                type="primary"
                @click="getDialogInfo(scope.row), (dialogVisible = true)"
                >修改信息</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </el-row>
    <el-button type="primary" @click="addUserDialogInfo = true"
      >添加用户</el-button
    >
    <el-dialog title="修改用户信息" :visible.sync="dialogVisible">
      <el-form :model="user">
        <el-form-item label="姓名：" :label-width="formLabelWidth">
          <el-input
            v-model="user.uname"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>

        <el-form-item label="用户名：" :label-width="formLabelWidth">
          <el-input
            v-model="user.uename"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>

        <el-form-item label="密码：" :label-width="formLabelWidth">
          <el-input
            type="password"
            v-model="user.upwd"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>

        <el-form-item label="状态：" :label-width="formLabelWidth">
          <el-input
            v-model="user.userOn"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="large">取 消</el-button>
        <el-button type="primary" @click="updateSelf()" size="large"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <el-dialog title="修改用户信息" :visible.sync="addUserDialogInfo">
      <el-form :model="insertuser">
        <el-form-item label="学院：" :label-width="formLabelWidth">
          <el-input
            v-model="insertuser.udept"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>

        <el-form-item label="姓名：" :label-width="formLabelWidth">
          <el-input
            v-model="insertuser.uname"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>

        <el-form-item label="用户名：" :label-width="formLabelWidth">
          <el-input
            v-model="insertuser.uename"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>

        <el-form-item label="密码：" :label-width="formLabelWidth">
          <el-input
            type="password"
            v-model="insertuser.upwd"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>

        <el-form-item label="状态：" :label-width="formLabelWidth">
          <el-input
            v-model="insertuser.userOn"
            autocomplete="off"
            placeholder=""
          ></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="large">取 消</el-button>
        <el-button type="primary" @click="addUser()" size="large"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import test from "@/api/index";

export default {
  data() {
    return {
      addUserDialogInfo: false,
      recordDialogVisible: false,
      formLabelWidth: "100px",
      dialogVisible: false,
      user: {
        uid: localStorage.getItem("id"),
        udept: "",
        uname: "",
        uename: "",
        upwd: "",
      },
      insertuser: {
        udept: "",
        uname: "",
        uename: "",
        upwd: "",
        userOn: "",
      },
      record: {
        uid: localStorage.getItem("id"),
        udept: "",
        uname: "",
        health: "",
        temperature: "",
        isOut: "",
        rtime: "",
        workState: "",
        remark: "",
      },

      recordList: [],
      absentUser: {
        uid: "",
        udept: "",
        uname: "",
        absenceCount: "",
        absenceTime: "",
      },
      absentUserlist: [],
      userlist: [],
    };
  },
  methods: {
    selectAllRecord() {
      test.selectAllRecord().then((response) => {
        if (response.status === 200) {
          this.recordList = response.data;
        }
      });
    },
    selectAbsentUser() {
      test.selectAbsentUser().then((response) => {
        if (response.status === 200) {
          console.log(response.data);
          for (var i = 0; i < response.data.length; i++) {
            if (response.data[i].absenceCount > 0) {
              
              this.absentUserlist.push(response.data[i]);
            }
          }
        }
      });
    },
    selectAllUser() {
      test.selectAllUser().then((response) => {
        if (response.status === 200) {
          this.userlist = response.data;
        }
      });
    },
    updateSelf() {
      test.updateSelf(this.user).then((response) => {
        if (response.status === 200) {
          this.dialogVisible = false;
        }
      });
    },

    getUserInfo() {
      test.getUserInfo(localStorage.getItem("id")).then((response) => {
        if (response.status === 200) {
          this.user = response.data;
          this.record.uname = this.user.uname;
          this.record.udept = this.user.udept;
          this.userlist.push(this.user);
        }
      });
    },
    getDialogInfo(obj) {
      test.UserLogin(obj.uid).then((response) => {
        if (response.status === 200) {
          this.user = response.data;
        }
      });
    },
    addUser() {
      console.log(this.insertuser);
      test.addUser(this.insertuser).then((response) => {
        if (response.status === 200) {
          this.addUserDialogInfo=false;
        }
      });
    },
  },

  created() {
    this.selectAllRecord();
    this.selectAbsentUser();
    this.selectAllUser();
  },
};
</script>

<style scoped>
.el-row {
  margin-bottom: 20px;
}

.grid-content {
  display: flex;
  align-items: center;
  height: 100px;
}

.grid-cont-right {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #999;
}

.grid-num {
  font-size: 30px;
  font-weight: bold;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.user-info {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.user-info-list {
  font-size: 14px;
  color: #999;
  line-height: 25px;
}

.user-info-list span {
  margin-left: 70px;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}

.schart {
  width: 100%;
  height: 300px;
}
</style>